package com.lrd.rmqcluster.schedule;

import com.lrd.rmqcluster.rmq5.testproducer.TestMessageProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Component
public class TestScheduleJob {

    private static final Logger log = LoggerFactory.getLogger(TestScheduleJob.class);

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    @Autowired
    private TestMessageProducer testMessageProducer;

    @Scheduled(cron = "* * * * * ?")
    public void sendMsg() {
        String key = LocalDateTime.now().format(FORMATTER);
        for (int i = 0; i < 10; i++) {
            String message = i + ":" + UUID.randomUUID();
            boolean result = testMessageProducer.sendMsg(message, key);
            log.info("定时发送mq消息key={},i={},result={}", key, i, result);
        }
    }
}
